﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using IDAL;
using Model;

namespace DAL
{
    public class PIMTestItem : BaseRepository<PIMTestItemInfo>, IPIMTestItem
    {
        private const string PARM_TEST_PRODUCTSN = "@ProductSN";
        private const string PARM_TEST_TESTTIME = "@TestTime";

        public IList<PIMTestItemInfo> GetPIMTestItembySNDT(string productSN, DateTime testTime)
        {
            SqlParameter[] testParms = GetSNTParameters();
            //Bind the parameter
            testParms[0].Value = productSN;
            testParms[1].Value = testTime;
            return ExcuteSqlToGetEntities("PIMTestItem_selectbySNDT", testParms);
        }

        private static SqlParameter[] GetSNTParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(PARM_TEST_PRODUCTSN, SqlDbType.NVarChar, 50),
					new SqlParameter(PARM_TEST_TESTTIME, SqlDbType.DateTime, 8)                
                };
            return parms;
        }

        //-------------------------------------重写超类基础操作---------------------------------------------------------

        public override PIMTestItemInfo GetEntityRecord(SqlDataReader rdr)
        {
            PIMTestItemInfo pro = new PIMTestItemInfo()
            {
                ProductSN = rdr.GetValue(0).ToString(),
                TestTime = rdr.GetDateTime(1),
                TopoAlias = rdr.GetValue(2).ToString(),
                InterceptOrder = rdr.GetValue(3).ToString(),
                InputPower1 = rdr.GetDecimal(4),
                InputPower2 = rdr.GetDecimal(5),
                InputF1 = rdr.GetDecimal(6),
                InputF2 = rdr.GetDecimal(7),
                OutputF = rdr.GetDecimal(8),
                TestValue = rdr.GetDecimal(9),
                HighSpec = rdr.GetDecimal(10),
                IsPass = rdr.GetValue(11).ToString(),
                IsCurrent = rdr.GetBoolean(12)
            };
            return pro;
        }




        #region 交调多频段测试临时库表相关
        //-------------------------------------以上为交调相关，以下为交调多频段测试相关-------------------------------------------------
        public IList<PIMTestItemInfo> GetPIMTestItem_tempbySNDT(string productSN, DateTime testTime)
        {
            SqlParameter[] testParms = GetSNTParameters();
            //Bind the parameter
            testParms[0].Value = productSN;
            testParms[1].Value = testTime;
            return ExcuteSqlToGetEntities("PIMTestItem_temp_selectbySNDT", testParms);
        }

        #endregion


        #region 二次交调相关
        //-------------------------------------以上为交调相关，以下为二次交调相关---------------------------------------------------------
        public IList<PIMTestItemInfo> GetPIMSecondTestItembySNDT(string productSN, DateTime testTime)
        {
            SqlParameter[] testParms = GetSNTParameters();
            //Bind the parameter
            testParms[0].Value = productSN;
            testParms[1].Value = testTime;
            return ExcuteSqlToGetEntities("PIMSecondTestItem_selectbySNDT", testParms);
        }

        #endregion
    }
}
